

const mongoose = require('mongoose');

var express = require('express')
// 注意这里的声明
var point = express()

const {createResponse}= require("../../util/createResponse/index");
const {businessCodes}= require("../../code/businessCodes/index");
const { pointService } = require('../../service/impl/pointService/index');





//#region  知识点 
/* 添加知识点 */
point.post('/post/tittlePoint/add', async (req,res) => {
  let result
  let id
  try {
    let news = req.body.news
    result =  await pointService.getIns().create(news)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })


/* 根据id删除知识点 */
point.post('/post/tittlePoint/delete',async (req,res) => {
  let result
  try {
    let  id  = req.body.conditions.id
    result =  await pointService.getIns().findByIdAndDelete(id)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })
/* 修改知识点 */
point.post('/post/tittlePoint/update',async (req,res) => {
  let result
  try {
    let  id  = req.body.conditions.id
    let updates = req.body.updates
    result =  await pointService.getIns().findByIdAndUpdate(id,updates)
  }catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })
/* 查询所有知识点 */
point.post('/post/tittlePoint/query',async (req,res) => {
  let result
  let fills ={
    "key1":{
      "path":"kemuid",
    },
    "key2":{
      "path":"xuekeid",
   }
  }

  try {
    result =  await pointService.getIns().find(null,null,fills)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })

/* 根据科目id查询知识点 */
point.post('/post/tittlePoint/queryPointsByKemuID',async (req,res) => {
  let result
  try {
    let conditions ={
      "kemuid":req.body.conditions.kemuid
    }
    result =  await pointService.getIns().find(conditions)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })
//#endregion


  
  
  
  //#endregion
  

  module.exports= point